<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	UserBean user = (UserBean)request.getSession().getAttribute("userBean");
	String _db = user.getDbType();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>参数配置</title>
	<meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>    
	<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
	<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
	<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
	<link type="text/css" rel="stylesheet" href="resource/css/style.css" />

	<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
	<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
	<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>
	<script type="text/javascript" src="js/common.js"></script>
	<script type="text/javascript" src="js/validata.js"></script>
	
	<script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
	<script type="text/javascript" src="ligerUI/js/plugins/ligerResizable.js"></script>
  
  <script type="text/javascript">
  var _db = '<%=_db%>';			
		_jsonObj.classname = "com.wxtf.platform.plugins.system_config.SystemConfig";
		_jsonObj.methodname = "queryPage";
		_jsonObj.extenddata = '';		
		var manager;
		$(function(){
			manager = $("#SystemConfig-grid").ligerGrid({
				url: _url, 
				parms: _jsonObj,
				dataAction:'server',method:'post',
				rownumbers:true,checkbox:true,enabledSort:true,
				width: '100%', height:'100%',
	            usePager:true,
	            alternatingRow: true,//奇偶行显示效果
	            columns: [
	            	{ display: 'sc_uuid', name: 'sc_uuid', hide: 1 },
	                { display: '级别',isSort:false,name: 'sc_uid',width: 100, align: 'left' ,render:function(record, index, value, oth){
	              			if(record.sc_uid=="0"){
	              				return '系统';
	              			}else{
	              				return '用户';
	              			}
	              		} 
	              	},
	                { display: 'sc_write_time', name: 'sc_write_time' , hide: 1 },
	                { display: '参数名',isSort:true,sortnameParmName:'sc_key',name: 'sc_key',id:'sc_key',width: 200, align: 'left'},
	                { display: '参数值',isSort:true,sortnameParmName:'sc_value', name: 'sc_value',  width: 200, align: 'left' },
	              	{ display: '是否可用',isSort:false,name: 'sc_marked', width: 120, align: 'left',render:function(record, index, value, oth){
	              			if(value=="1"){
	              				return '可用';
	              			}else if(value=="0"){
	              				return '不可用';
	              			}
	              		} 
	              	},
	               	{ display: '编辑',isSort:false,name:'edit',width:80,render:function(record, index, value, oth){
	              			return '<a href="javascript:bianji(\''+record.sc_uuid+'\',\'' + record.sc_key + '\',\''+record.sc_value+'\',\'' + record.sc_marked + '\')"  class="edit_btn_div" onmouseover="this.className=\'edit_btn_div_over\'" onmouseout="this.className=\'edit_btn_div\'"><img src="ligerUI/skins/icons/edit.gif"/></div>';
	               		}
	                }
	            ]
	            /*
	            ,
	            toolbar: { items: [
                	{ text: '新建', click: add, icon: 'add' },
                	{ line: true },
                	{ text: '删除', click: del, icon: 'delete'}
                	]
                }
                */
	        });	           
	    });
	        var win1;
       	//打开窗口	        
        function f_openWindow1(target, title, width, height, func, func2) {
			if(win1==null){
            	win1 = initWindowByDiv(target, title, width, height, func, func2);
			}else{
				win1.show();
			}
       	}
       	var win;
       	//打开窗口	        
        function f_openWindow(target, title, width, height, func, func2) {
			if(win==null){
            	win = initWindowByDiv(target, title, width, height, func, func2);
			}else{
				win.show();
			}
       	}
	    function add(){
			document.forms[1].reset();
			var param = { 
				"classname": "com.wxtf.platform.plugins.system_config.SystemConfig",
				"methodname": "save",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			
			f_openWindow('edit1', '新建窗口', 350, 200 ,function(){					
					var esc_key = $("#esc_key").val();
					var esc_value = $("#esc_value").val();
					var esc_marked = $(":radio[name='esc_marked']:checked").val();
					if(fucCheckLength(esc_key.trim()) <= 0 || fucCheckLength(esc_key.trim()) > 200){
						warningTip("参数名称：不能为空且不能超过200字符");
						return;
					}
					if(fucCheckLength(esc_value.trim()) <= 0 || fucCheckLength(esc_value.trim()) > 100){
						warningTip("参数值：不能为空且不能超过100字符");
						return;
					}
					if(!checkIsVar(esc_key)){
						warningTip("参数名只能是数字、字母、下划线组成,且不能以数字开头");
						return;
					}
					param.logicdata = '[{"esc_key":"'+esc_key+'","esc_value":"'+esc_value+'","esc_marked":"'+esc_marked+'"}]';
					callserver(param,function(data, satus){
						succMsgTip(data.resultrecord);
						reload();
						win.hide();
					},function(data, satus){
						warningTip(data.resultrecord);
					});
			}, function(){
				win.hide();
			});
		}
		function bianji(usc_uuid,usc_key,usc_value,usc_marked){
			document.forms[0].reset();
			$("#sc_uuid").val(usc_uuid);
			$("#sc_key").val(usc_key);
			$("#sc_value").val(usc_value);
			if(usc_marked=="1"){
				document.getElementById('a1').innerHTML = '<input type="radio" name="sc_marked" value="1" checked="checked"/>是<input type="radio" name="sc_marked" value="0"/>否';
			}else if(usc_marked=="0"){
				document.getElementById('a1').innerHTML = '<input type="radio" name="sc_marked" value="1"/>是<input type="radio" name="sc_marked" value="0" checked="checked"/>否';
			}
			var param = { 
				"classname": "com.wxtf.platform.plugins.system_config.SystemConfig",
				"methodname": "update",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			f_openWindow1('edit', '编辑窗口', 350, 200,function(){
					var sc_uuid = $("#sc_uuid").val();
					var sc_keyhide = $("#sc_keyhide").val();
					var sc_key = $("#sc_key").val();
					var sc_value = $("#sc_value").val();
					var sc_marked = $(":radio[name='sc_marked']:checked").val();
					if(fucCheckLength(sc_value.trim()) <= 0 || fucCheckLength(sc_value.trim()) > 100){
						warningTip("参数值：不能为空且不能超过100字符");
						return;
					}
					param.logicdata = '[{"sc_uuid":"'+sc_uuid+'","sc_key":"'+sc_key+'","sc_value":"'+sc_value+'","sc_marked":"'+sc_marked+'"}]';
					callserver(param,function(data, satus){
						$("#editForm input,.l-textarea").ligerHideTip();
						succMsgTip(data.resultrecord);
						reload();
						win1.hide();
					},function(data, satus){
						warningTip(data.resultrecord);
					});
			}, function(){
				win1.hide();
			});
		}
	        //页面刷新方法
	        function reload(){
	        	_jsonObj.methodname = "queryPage";
				_jsonObj.extenddata = '';
				manager.loadData();
	        }
			
			//删除方法
			function del(){
				var row = manager.getCheckedRows();
				var str = "";
				var s = "";
				$(row).each(function (){
        	    	str += this.sc_uuid + ",";
        	    	if(this.sc_uid=="0"){
        	    		s+=this.sc_key+","
        	    	}
        		});
        		s=s.substring(0,s.length-1);
        		if(s!=""){
        			$.ligerDialog.warn(s+"是系统参数，不可删除");
					return;
        		}
        		str=str.substring(0,str.length-1);
        		if(str==""){
					$.ligerDialog.warn("没有选中项");
					return;
				}
	        	$.ligerDialog.confirm('确认删除操作吗?', function (ml) { 			
					if(ml==true){
		       			if(str!=""){
		       				//定义删除的参数
	            			var param = {
								"classname": "com.wxtf.platform.plugins.system_config.SystemConfig",
								"methodname": "delete",
								"logicdata": [],
								"extenddata": []
							};
							param.logicdata = '[{"ids":"'+str+'"}]';
  							callserver(param,function(data, satus){
								succMsgTip(data.resultrecord);
								reload();
							},function(data, satus){
								warningTip(data.resultrecord);
							});
						}
					}
				});                    
			}
  </script>
   </head>
  <body>
   <div id="SystemConfig-grid"></div>
    <div id="edit" style="display:none;">
			<form id="editForm">
			<input type="hidden" name="sc_uuid" id="sc_uuid"/>
			<input type="hidden" name="sc_keyhide" id="sc_keyhide"/>
				<table class="form_table">
					<tr >
						<td class="form_label">参数名：</td>
						<td>
							<input disabled="disabled" type="text" name="sc_key" id="sc_key" class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/>
					    </td>
					</tr>
					<tr>
						<td class="form_label">参数值：</td>
						<td >
						    <input type="text" name="sc_value" id="sc_value" class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/>
						</td>
					</tr>
					<tr >
						<td class="form_label">是否可用：</td>
						<td id="a1" align="left">
							
					    </td>
					</tr>
				</table>
			</form>			
		</div>
		<div id="edit1" style="display:none;">
			<form id="editForm1">
				<table class="form_table">
					<tr >
						<td class="form_label">参数名：</td>
						<td>
							<input type="text" name="esc_key" id="esc_key" class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/>
					    </td>
					</tr>
					<tr>
						<td class="form_label">参数值：</td>
						<td>
						    <input type="text" name="esc_value" id="esc_value" class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/>
						</td>
					</tr>
					<tr >
						<td class="form_label">是否可用：</td>
						<td align="left">
						    <input type="radio" name="esc_marked" value="1" checked="checked"/>是
							<input type="radio" name="esc_marked" value="0"  />否
					    </td>
					</tr>
				</table>
			</form>			
		</div>
  </body>
</html>
